﻿using System;
using System.Web.UI.WebControls;
using SARS.Biz;
using SARS.Biz.Facades;
using SARS.Entity;

namespace SARS.Course.Group
{
    public partial class SelectGroupToAssign : System.Web.UI.Page
    {
        IGroupBO groupBiz = new GroupBO();

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetNoStore();
            if (Session["Roles"] == null || RoleType.Coordinator != (RoleType)Session["Roles"])
            {
                Response.Write("<script language='javascript'>window.alert('Your role is not allow to access this page.');" +
                               "window.location='../../Account/Login.aspx';</script>");

            }
        }

        protected void ucProgramCourse_OnSelectedCourseChanged()
        {
            BindingGridView();
        }

        protected void OnClick(object sender, EventArgs e)
        {
            LinkButton btnSelect = sender as LinkButton;
            if (btnSelect != null)
            {
                GridViewRow row = (GridViewRow)btnSelect.NamingContainer;

                string id = row.Cells[0].Text;
                Response.Redirect("AssignStudentGroup.aspx?gid=" + id);
            }
        }

        private void BindingGridView()
        {
            gvGroupList.DataSource = groupBiz.RetriveAllGroupByCourseId(ucProgramCourse.SelectedCourseValue);
            gvGroupList.DataBind();
        }

        protected void Detail_OnClick(object sender, EventArgs e)
        {
            LinkButton btnDetail = sender as LinkButton;
            if (btnDetail != null)
            {
                GridViewRow row = (GridViewRow)btnDetail.NamingContainer;

                string id = row.Cells[0].Text;
                Response.Redirect("StudentGroupDetail.aspx?gid=" + id);
            }
        }
    }
}